﻿/**
 * 加载数据
 */
$(function() {
	getSource(0);
});
function getSource(fdeleted){
	$("div[class=holder]").myPagination({
		currPage: 1,
		pageNumber: 15,
		cssStyle:'grayr',
		limit : 10,
		panel:{
			tipInfo_on:true,
			tipInfo_css:{
				width:"22px",height:'12px'
			}
		},
		ajax: {
		  on: true,
		  url: "list",
		  dataType: 'json',
		  param :"fdeleted=0",
		  ajaxStart:function(){
			  ZENG.msgbox.show(" 正在加载中，请稍后...", 6, 10000);
		  },onClick:function(page){
			  $.fn.debug(page);
		  },
		  callback:function(data){
			  ZENG.msgbox.hide(); //隐藏加载提示
			  $.fn.debug(data.source);
			  bindGridList(data);
		  }
		}
	}); 
}

var defaultImg = '/CMS/images/imgprew.png';
function bindGridList(data){
	//$("#total").html('总共找到'+data.total+'条数据');
	var html = "";
	if(data.total > 0){
		$.each(data.source,function(i,website){
			html +='<tr id="web'+i+'" class="tableContent" onclick="ischecked(this)">';// ondblclick="editAjax('+website.id+')"
			html +='<td style="padding-left: 5px;"><input type="checkbox" name="web" onchange="checkedInput(this)" onclick="ischecked(document.getElementById(\'web'+i+'\'))" id="td'+ i +'" value="'+website.id+'"/></td>';
			html +='<td>'+website.ftitle+'</td>';
			html +='<td>'+website.fcreatetime+'</td>';
			html +='<td>'+website.falias+'</td>';
			html +='<td>'+website.fintro+'</td>';
			html +='<td align="center"><a href="http://'+data.portalIp+'/'+website.falias+'/" target="_blank">预览</a></td>';
			html +='<td align="center"><a href="javascript:void(0);" onclick="queryTerminal('+website.id+');">查看</a></td></tr>';
		});
	}else{
		html = "<tr><td colspan='7' align='center'>暂无数据</td></tr>";
	}
	$("#websites").html(html);
}
/**
 * 选中子元素
 * @param obj
 */
function check(obj,name,tableContent){
	name = name == undefined ? "web" : name;
	tableContent = tableContent == undefined ? "tableContent" : tableContent;
	var checkbox = $("[name='"+name+"']");
	if(obj.checked){
		checkbox.attr("checked",'true');//全选 
		$("[class="+tableContent+"]").css("background-color","#D8F79D");
	}else{
		checkbox.removeAttr("checked");//取消全选 
		$("[class="+tableContent+"]").css("background-color","");
	}
}
/**
 * 当前选中项
 * @param obj
 */
function checkedInput(obj,name,select){
	name = name == undefined ? "web" : name;
	select = select == undefined ? "td" : select;
	var id = obj.id.replace(select,"");
	if(obj.checked)
		$("#"+name+id).css("background-color","#D8F79D");
	else
		$("#"+name+id).css("background-color","");
		
}
/**
 * 单击行时，选中的则取消，未选中的则选中
 * @param obj
 */
function ischecked(obj,name,tdId){
	name = name == undefined ? "web" : name;
	tdId = tdId == undefined ? "td" : tdId;
	var id = obj.id;
	var trObj = $("#"+id);
	tdId = tdId+id.replace(name,"");
	var objCheck = $("#"+tdId);
	if(objCheck.attr("checked")){
		objCheck.removeAttr("checked");//取消选中 
		trObj.css("background-color","");
	}else{
		objCheck.attr("checked",'true');//选中
		trObj.css("background-color","#D8F79D");
	}
}
/**
 * 获取所有选中的id
 * @returns {Array}
 */
function checkedInfo(name){
	name = name == undefined ? "web" : name;
	var ids = new Array();
	$("[name='"+name+"'][checked]").each(function(){  
		ids.push($(this).val());  
	}); 
	return ids;  
}
/**
 * 获取所有选中的name
 * @returns {Array}
 */
function checkedInfoNames(name){
	name = name == undefined ? "web" : name;
	var names = new Array();
	$("[name='"+name+"'][checked]").each(function(){  
		names.push($(this).attr("class"));  
	}); 
	return names;  
}
/**
 * 添加网站页面
 */

function addWebsiteHtml(data){
	var table = '<form action="addWebsite" method="post" name="websiteForm" id="websiteForm" onsubmit="return formIsNull(this);">';
		table += '<div class="tab-page" id="baseinfo" style="display: block;">';
		table += '<table width="630" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">';
	    table += '<tr><td width="100">站点名称</td><td><input class="text" name="ftitle" type="text" id="ftitle" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/></td></tr>';
	    table += '<tr><td height="30">站点目录</td><td height="30"><input class="text" name="falias" type="text" id="falias" value="" size="30"  style="border: 0;border-bottom: 1px solid #ABADB3;" onchange="hasAlias(this.value);"/><span id="hasAlias"></span><font color="#666666">(使用字母/数字,如：site)</font></td></tr>';
	    table += '<tr><td height="30">视频服务器地址</td><td height="30"><input class="text" name="fvideoip" type="text" id="fvideoip" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：127.0.0.1)</font></td></tr>';
	    table += '<tr><td height="30">视频服务器端口</td><td height="30"><input class="text" name="fvideoport" type="text" id="fvideoport" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：554)</font></td></tr>';
	    table += '<tr><td height="30">设备名称</td><td height="30"><input name="fterminalId" type="hidden" id="fterminalId"><input name="fterminal" type="text" id="fterminal" readonly="readonly" size="25" value=" " style="border: 0;border-bottom: 1px solid #ABADB3;"/><input type="button" value="添加设备" onclick="selectTerminalUnit();"></td></tr>';
	    //table += '<tr><td height="30">视频路径</td><td height="30"><input name="fmoviepath" type="text" id="fmoviepath" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：/d/file/)</font></td></tr>';
	    //table += '<tr> <td height="30">音频路径</td><td height="30"><input name="faudiopath" type="text" id="faudiopath" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：/d/file/)</font></td></tr>';
	    //table += '<tr><td height="30">图片路径</td><td height="30"><input name="fimagepath" type="text" id="fimagepath" value="" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：/d/file/)</font></td></tr>';
//	    table += '<tr><td height="30">网站首页模版</td><td height="30"><input class="text" name="ftemplateid" type="hidden" id="ftemplateid" value=""/><img src="'+defaultImg+'" width="140" height="100" id="ftemplatesrc" style="display:none;"><input name="template" id="template" type="button" value="选择模版..." onclick="getTemplate();" ></td></tr>';
	    table += '<tr><td height="30">网站首页模版</td><td height="30"><select name="ftemplateid">';
	    $.each(data,function(i,temp){
	    	table += "<option value='"+temp.id+"'>"+temp.fname + "</option>";
	    });
	    /*for (var i in str){ 
	    	table += "<option value='"+str[i]+"'>"+str[i] + "</option>";
	    }*/
	    table += '</select></td></tr>';
	    table += '<tr><td height="30">生成静态页面</td><td height="30"><input type="checkbox" name="fstaticpage" value="1"/></td></tr>';
	   // table += '<tr><td height="30">生成单向数据广播</td><td height="30"><input name="fdatabroadcasting" type="checkbox" id="fdatabroadcasting" value="1"/></td></tr>';
	    table += '<tr><td height="30">网站简介</td><td height="30"><textarea name="fintro" id="fintro" style="width:350px;height:50px;resize:none"></textarea></td></tr>';
	    table += '</table></div></form>';
	return table;
}
/**
 * 检查别名是否重复
 */
function hasAlias(val){
	var hasAlias = $("#hasAlias");
	var alias = $("#falias");
	hasAlias.html("");
	if(!val){
		hasAlias.html("站点名不能为空");
		hasAlias.css("color","red");
		alias.focus();
	}else{
		$.ajax({
			url:"hasAlias",
			type:"post",
			data : {"alias":val},
			success:function(data){
				if(data.trim()=="use"){
					hasAlias.html("该站点名已被使用");
					hasAlias.css("color","red");
					alias.focus();
				}else{
					hasAlias.html("");
				}
			},
			error:function(data){
				$.growlUI("数据加载出错"); 
			}
		
		});
	}
}

/**
 * 获取模版信息
 */
function getTemplate(){
	$.ajax({
		url:"../template/query",
		data:{"limit":1000},
		type:"post",
		dataType:"json",
		success:function(data){
			bindGridTemplate(data);
		},
		error:function(data){
			$.growlUI("数据加载出错"); 
		}
	
	});
}
/**
 * 提交保存网站数据
 */
function submitWebsite(uri){
	if(formIsNull($("#websiteForm")))
		$("#websiteForm").ajaxSubmit({
			url:uri,
			type:'post',
			dataType:'json',
			success:function(data){
				if(data=="-1"){
					self.location.href="pay";
				}else{
					$('a[title=1]').click();
					$("#cancel").click();
					$.growlUI('数据保存成功');
				}
			},
			error:function(msg){
				$.growlUI('数据保存失败'); 
			}
		});
}
/**
 * 绑定数据
 * @param data
 */
function bindGridTemplate(data){
	var html = '';
	$.each(data.source,function(i,template){
		html += template.fname + ",";
	});
	//alert(html);
	var div = "<div id='template' style='width:700px;'><img src='/CMS/templateImage/1.jpg' alt='' height='150' width='220' onclick='setTemplateValue(1,this.src);'/>";
	/*div += 	"<img src='/CMS/test/2.jpg' alt='' width='220' height='150' onclick='setTemplateValue(2,this.src);'/>";
	div += 	"<img src='/CMS/test/4.jpg' alt='' width='220' height='150' onclick='setTemplateValue(3,this.src);'/>";
	div += 	"<img src='/CMS/test/5.jpg' alt='' width='220' height='150' onclick='setTemplateValue(4,this.src);'/>";
	div += 	"<img src='/CMS/test/6.jpg' alt='' width='220' height='150' onclick='setTemplateValue(5,this.src);'/>";*/
	//div += 	"<img src='/CMS/test/7.jpg' alt='' width='220' height='150' onclick='setTemplateValue(6,this.src);'/></div>";
	div += "</div>";
	Box("templateImg",700,350,div,"&nbsp;",999,920);
}
/**
 * 选择模版，关闭模版层
 * @param id
 * @param val
 */
function setTemplateValue(id,val){
	$("#ftemplateid").val(id);//模版id
	$("#ftemplatesrc").attr("src",val);//设置模版值
	$("#ftemplatesrc").css("display","");
	$box("templateImgcloseBtn").click();//关闭模版
}
/**
 * 加载数据
 * @param id
 */
function addWebsite(){
	$.ajax({
		url:"addIndex",
		type:"post",
		dataType:"json",
		success:function(data){
			addIndex(data);
		},
		error:function(data){
			$.growlUI('数据加载出错'); 
		}
	
	});
}
/**
 * 添加网站弹出信息
 */
function addIndex(data){
	var html = addWebsiteHtml(data);
	var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'templateHtmlcloseBtn\').onclick();"/>&nbsp;&nbsp;&nbsp;<input type="image" alt="Submit" src="/CMS/images/box/submit_button.jpg" class="btn" id="submit" onclick="submitWebsite(\'addWebsite\')" />';
	Box("templateHtml",650,350,html,footerhtml,910);
}
/**
 * 加载数据
 * @param id
 */
function editAjax(id){
	var data = {"id":id};
	$.ajax({
		url:"queryWebsiteById",
		data:data,
		type:"post",
		dataType:"json",
		success:function(data){
			bindGridEdit(data);
		},
		error:function(data){
			$.growlUI('数据加载出错'); 
		}
	
	});
}
/**
 * 编辑加载数据
 * @param id
 */
function editWebsite(id){
	var ids = checkedInfo();
	if(ids.length == 1){
		editAjax(ids[0]);
	}else if(ids.length == 0){
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择要修改的网站</div>";	
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'editHtmlcloseBtn\').onclick();"/>';
		Box("editHtml",10,10,html,footerhtml,901);
	}else if(ids.length > 1){
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;只能修改1条信息！</div>";
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'editHtmlcloseBtn\').onclick();"/>';
		Box("editHtml",10,10,html,footerhtml,901);
	}
}
/**
 * 绑定编辑数据
 * @param data
 */
function bindGridEdit(data){
	var website = data.website;
	var checked = "checked='checked'";
	var id = '';
	var name = '';
	//编列设备数据
	$.each(data.terminal,function(i,terminal){
		id += terminal.id + ',';
		name += terminal.fname + ',';
	});
	id= id.substring(0, id.length-1);
	name= name.substring(0, name.length-1);
	var table = '<form action="updateWebsite" method="post" name="websiteForm" id="websiteForm" onsubmit="return formIsNull(this);">';
	table += '<div class="tab-page" id="baseinfo" style="display: block;">';
	table += '<table width="550" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">';
    table += '<tr><td width="100">站点名称</td><td><input class="text" name="ftitle" type="text" id="ftitle" value="'+website.ftitle+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><input name="id" type="hidden" id="id" value="'+website.id+'"/></td></tr>';
    table += '<tr><td height="30">站点目录</td><td height="30"><input class="text" name="falias" type="text" id="falias" value="'+website.falias+'" size="30"  style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(使用字母/数字,如：website)</font></td></tr>';
    table += '<tr><td height="30">视频服务器地址</td><td height="30"><input class="text" name="fvideoip" type="text" id="fvideoip" value="'+website.fvideoip+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：127.0.0.1)</font></td></tr>';
    table += '<tr><td height="30">视频服务器端口</td><td height="30"><input class="text" name="fvideoport" type="text" id="fvideoport" value="'+website.fvideoport+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：554)</font></td></tr>';
    table += '<tr><td height="30">设备名称</td><td height="30"><input name="fterminalId" value="'+id+'" type="hidden" id="fterminalId"><input name="fterminal" type="text" id="fterminal" readonly="readonly" size="30" value="'+name+'" style="border: 0;border-bottom: 1px solid #ABADB3;"/><input type="button" value="修改设备" onclick="selectTerminalUnit();"></td></tr>';
    
    //table += '<tr><td height="30">视频路径</td><td height="30"><input name="fmoviepath" type="text" id="fmoviepath" value="'+website.fmoviepath+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：/d/file/)</font></td></tr>';
    //table += '<tr> <td height="30">音频路径</td><td height="30"><input name="faudiopath" type="text" id="faudiopath" value="'+website.faudiopath+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：/d/file/)</font></td></tr>';
    //table += '<tr><td height="30">图片路径</td><td height="30"><input name="fimagepath" type="text" id="fimagepath" value="'+website.fimagepath+'" size="30" style="border: 0;border-bottom: 1px solid #ABADB3;"/><font color="#666666">(如：/d/file/)</font></td></tr>';
   
    //table += '<tr><td height="30">网站首页模版</td><td height="30"><input class="text" name="ftemplateid" type="hidden" id="ftemplateid" value="'+website.ftemplateid+'"/><img src="'+defaultImg+'" width="140" height="100" id="ftemplatesrc"><input name="template" id="template" type="button" value="修改" onclick="getTemplate();" ></td></tr>';
    table += '<tr><td height="30">网站首页模版</td><td height="30"><select name="ftemplateid">';
    $.each(data.template,function(i,temp){
    	table += "<option value='"+temp.id+"' "+(temp.id==website.ftemplateid?'selected=\"selected\"':'')+">"+temp.fname + "</option>";
    });
    table += '</select></td></tr>';
    table += '<tr><td height="30">生成静态页面</td><td height="30"><input type="checkbox" name="fstaticpage" value="1"'+(website.fstaticpage==0?"":checked)+'/></td></tr>';
    //table += '<tr><td height="30">生成单向数据广播</td><td height="30"><input name="fdatabroadcasting" type="checkbox" id="fdatabroadcasting" value="1" '+(website.fdatabroadcasting==0?"":checked)+'/></td></tr>';
    table += '<tr><td height="30">网站简介</td><td height="30"><textarea name="fintro" id="fintro" style="width:350px;height:50px;resize:none">'+website.fintro+'</textarea></td></tr>';
    table += '</table></div></form>';
	var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'templateHtmlcloseBtn\').onclick();"/>&nbsp;&nbsp;&nbsp;<input type="image" alt="Submit" src="/CMS/images/box/submit_button.jpg" class="btn" id="submit" onclick="submitWebsite(\'updateWebsite\')" />';
	Box("templateHtml",600,350,table,footerhtml,910);
}
/**
 * 删除站点信息
 */
function deleteWebsite(){
	var ids = checkedInfo();
	if(ids.length > 0){
		if(confirm("确定要删除网站信息吗？删除后无法恢复！")){
			var s = "";
		    for(var i=0;i<ids.length ;i++){
		        s +=ids[i]+",";
		    }
		    if(s != ""){
		    	s = s.substring(0,s.length-1) ;
		    }
			var data = {"ids":s};
			$.ajax({
				url:"deleteWebsite",
				data:data,
				type:"post",
				success:function(data){
					$.growlUI('成功删除数据'+data+'条');
					/*getSource(1);*/
					$('a[title=1]').click();
				},
				error:function(data){
					$.growlUI('数据删除失败'); 
				}
			
			});
			$("input[name=weball]").attr("checked",false);
		}
	}else{
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择要删除的信息</div>";
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'deleteHtmlcloseBtn\').onclick();"/>';
		Box("deleteHtml",10,10,html,footerhtml,901);
	}
}
/**
 *已删除的数据
 */
function getDeleteSource(start,limit){
	this.dustbin = "dustbin";
	start = start == undefined ? 0 : start;
	var data = {"start": start,"limit":limit,"fdeleted":1};
	$.ajax({
		url:"list",
		data:data,
		type:"post",
		dataType:"json",
		success:function(data){
			bindGridDeleteList(data);
			if(!limit)
				page(data.total,data.limit,1,"pager","getDeleteSource",true);
		},
		error:function(data){
			$.growlUI('数据加载出错'); 
		}
	});
}
function bindGridDeleteList(data){
	$("#total").html('总共找到'+data.total+'条数据');
	var html = "";
	$.each(data.source,function(i,website){
		html +='<tr id="web'+i+'" class="tableContent" onclick="ischecked(this)" ondblclick="editAjax('+website.id+')">';
		html +='<td style="padding-left: 5px;"><input type="checkbox" name="web" onchange="checkedInput(this)" onclick="ischecked(document.getElementById(\'web'+i+'\'))" id="td'+ i +'" value="'+website.id+'"/></td>';
		html +='<td>'+website.ftitle+'</td>';
		html +='<td>'+website.fcreatetime+'</td>';
		html +='<td>'+website.falias+'</td>';
		html +='<td>'+website.fintro+'</td></tr>';
	});
	$("#websites").html(html);
}
/**
 * 修改或删除
 */
function deleteDustbinWebsite(deleted){
	var ids = checkedInfo();
	if(ids.length > 0){
		var s = "";
	    for(var i=0;i<ids.length ;i++){
	        s +=ids[i]+",";
	    }
	    if(s != ""){
	    	s = s.substring(0,s.length-1) ;
	    }
		var data = {"ids":s,"deleted":deleted};
		$.ajax({
			url:"deleteDustbinWebsite",
			type:'post',
			dataType:'json',
			data : data,
			success:function(data){
				$.growlUI('操作'+data+'条数据成功');
				/*if(deleted == 1)
					getSource(0);
				else
					getSource(1);*/
				$('a[title=1]').click();
			},
			error:function(msg){
				$.growlUI('数据操作失败'); 
			}
		});
	}else{
		var html = "<div style='vertical-align: middle;'><img src='/CMS/images/box/icon_alert.gif' alt='提示'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请选择要操作的信息</div>";
		var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancel" onclick="$box(\'deleteHtmlcloseBtn\').onclick();"/>';
		Box("deleteHtml",10,10,html,footerhtml,901);
	}
}
/***
 * 获取设备信息
 */
function selectTerminalUnit(){
	var data = {"fdevicetype":1};
	$.ajax({
		url:"terminalList",
		type:'post',
		dataType:'json',
		data : data,
		success:function(data){
			boxTerminal();
			bindGridTerminal(data);
		},
		error:function(msg){
			$.growlUI('数据操作失败'); 
		}
	});
}
/***
 * 绑定设备数据
 * @param data
 */
function bindGridTerminal(data){
	$("#totleTerminal").html('总共找到'+data.total+'条数据');
	var html = '';
	$.each(data.source,function(i,terminal){
		html += '<tr id="terminal'+i+'" class="terminalContent" onclick="ischecked(this,\'terminal\',\'select\')">';
		html +='<td style="padding-left: 5px;"><input type="checkbox" name="terminal" onchange="checkedInput(this,this.name,\'select\')" onclick="ischecked(document.getElementById(\'terminal'+i+'\',this.name))" id="select'+ i +'" value="'+terminal.id+'" class="'+terminal.fname+'"/></td>';
		html += '<td>'+(terminal.fname == undefined ? "" : terminal.fname)+'</td>';
		if(terminal.fdevicetype == 0){
			html += '<td>电脑</td>';
		}else if(terminal.fdevicetype == 1){
			html += '<td>机顶盒</td>';
		}else if(terminal.fdevicetype == 2){
			html += '<td>手机</td>';
		}else if(terminal.fdevicetype == 3){
			html += '<td>Pad</td>';
		}
		html += "<td>"+(terminal.fdevicetype != 1 ? "" : terminal.ftype == undefined? "" :terminal.ftype == 'HD' ? '高清':'标清 ') +"</td>";
		html += "<td>"+(terminal.fdevicetype != 1 ? "" : terminal.ffont == undefined? "" :terminal.ffont==0 ?'点阵['+terminal.ffontsize+'px]':'矢量')+"</td>";
		html += "<td>"+(terminal.fdevicetype != 1 ? "" : terminal.fresolutionx == undefined? "": terminal.fresolutionx+'×'+terminal.fresolutiony)+'</td>';
		html += "<td>"+terminal.fmodel+'</td>';
		html += "<td>"+terminal.fcompany+'</td></tr>';
	});
	$("#dataTerminal").html(html);
}
/**
 * 数据填充框架
 */
function boxTerminal(){
	var opt = '<form action="terminalList" id="terminalForm">&nbsp;全选<input type="checkbox" name="weball" value="2" onchange="check(this,\'terminal\',\'terminalContent\');"/>';
		opt += '&nbsp;&nbsp;设备类型:<select name="fdevicetype" style="width:100px;" onchange="terminalFtype(this.value)"><option></option><option value="0">电脑</option><option value="1" selected>机顶盒</option><option value="2">手机</option><option value="3">Pad</option></select>';
		opt += '<span id="hid" style="width:400px;">&nbsp;解析度:<select name="ftype" style="width:100px;"><option></option><option value="HD">高清</option><option value="SD">标清</option></select>';
		opt += '&nbsp;字库:<select name="ffont" style="width:100px;"><option></option><option value="1">矢量</option><option value="0">点阵</option></select></span>';
		opt += '&nbsp;关键词: <input name="fname" id="fname" style="width: 110px;" type="text"><input class="inputButton" name="submitbutton" value="查询" onclick="getTerminal()" id="submitbutton" type="button"></span></form>';
	var html = '<div class="tableBox"><table border="0" width="100%" rules="none" cellspacing="0" cellpadding="0">';
		html += '<tr><th colspan="8">设备列表</td></tr>';
		html += '<tr><td colspan="8" style="border: 1px solid #B4C9C6;" id="opt">'+opt+'</td></tr>';
		html += '<tr><th class="th"></th><th class="th">设备名称</th><th class="th">设备类型</th><th class="th">解析度</th><th class="th">字库</th><th class="th">分辨率</th><th class="th">设备型号</th><th class="th">生成厂家</th></tr>';
		html += '<tbody id="dataTerminal"></tbody>';
		html +='<tr><td colspan="8" id="totleTerminal"></td></tr></table></div>';
	var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancelTerminal" onclick="$box(\'terminalHtmlcloseBtn\').onclick();"/>&nbsp;&nbsp;&nbsp;<input type="image" alt="Submit" src="/CMS/images/box/submit_button.jpg" class="btn" id="submit" onclick="setTerminal()" />';
	Box("terminalHtml",900,350,html,footerhtml,916,915);
}
/**
 * 为stb时隐藏
 * @param obj
 */
function terminalFtype(val,hid){
	hid = hid == undefined ? "hid" : hid;
	if(val==1){
		$("#"+hid).css("display","");
	}else{
		$("#"+hid).css("display","none");
	}
}
/**
 * 条件查询设备信息
 */
function getTerminal(){
	$("#terminalForm").ajaxSubmit({
		url:"terminalList",
		type:'post',
		dataType:'json',
		success:function(data){
			bindGridTerminal(data);
		},
		error:function(msg){
			$.growlUI('设备数据获取失败'); 
		}
	});
}
/**
 * 设置设备值
 */
function setTerminal(){
	var ids = checkedInfo("terminal");
	var names = checkedInfoNames("terminal");
	var id = "";
    for(var i=0;i<ids.length ;i++){
    	id +=ids[i]+",";
    }
    if(id != ""){
    	id = id.substring(0,id.length-1) ;
    }
    var name = "";
    for(var i=0;i<ids.length ;i++){
    	name +=names[i]+",";
    }
    if(name != ""){
    	name = name.substring(0,name.length-1) ;
    }
    $("#fterminalId").val(id);
    $("#fterminal").val(name);
    $("#cancelTerminal").click();
}
/**
 * 根据网站id查询设备列表
 * @param id
 */
function queryTerminal(websiteId){
	var data = {"fwebsiteid":websiteId};
	$.ajax({
		url:"queryTerminal",
		type:'post',
		dataType:'json',
		data : data,
		success:function(data){
			bindGridWebsiteTerminal(data);
		},
		error:function(msg){
			$.growlUI('数据操作失败'); 
		}
	});
}
/***
 * 绑定设备数据
 * @param data
 */
function bindGridWebsiteTerminal(data){
	var html = '<div class="tableBox"><table border="0" width="100%" height="80" rules="none" cellspacing="0" cellpadding="0">';
	html += '<tr height="30"><th colspan="8">设备列表</th></tr>';
	html += '<tr height="30"><th class="th">设备名称</th><th class="th">设备类型</th><th class="th">解析度</th><th class="th">字库</th><th class="th">分辨率</th><th class="th">设备型号</th><th class="th">生成厂家</th></tr>';
	$.each(data.source,function(i,terminal){
		html += '<tr id="terminal'+i+'" class="terminalContent" height="30">';
		//html +='<td style="padding-left: 5px;"><input type="checkbox" name="terminal" onchange="checkedInput(this,this.name,\'select\')" onclick="ischecked(document.getElementById(\'terminal'+i+'\',this.name))" id="select'+ i +'" value="'+terminal.id+'" class="'+terminal.fname+'"/></td>';
		html += '<td>'+(terminal.fname == undefined ? "" : terminal.fname)+'</td>';
		if(terminal.fdevicetype == 0){
			html += '<td>电脑</td>';
		}else if(terminal.fdevicetype == 1){
			html += '<td>机顶盒</td>';
		}else if(terminal.fdevicetype == 2){
			html += '<td>手机</td>';
		}else if(terminal.fdevicetype == 3){
			html += '<td>Pad</td>';
		}
		html += "<td>"+(terminal.fdevicetype != 1 ? "" : terminal.ftype == undefined? "" :terminal.ftype == 'HD' ? '高清':'标清 ') +"</td>";
		html += "<td>"+(terminal.fdevicetype != 1 ? "" : terminal.ffont == undefined? "" :terminal.ffont==0 ?'点阵['+terminal.ffontsize+'px]':'矢量')+"</td>";
		html += "<td>"+(terminal.fdevicetype != 1 ? "" : terminal.fresolutionx == undefined? "": terminal.fresolutionx+'×'+terminal.fresolutiony)+'</td>';
		html += "<td>"+terminal.fmodel+'</td>';
		html += "<td>"+terminal.fcompany+'</td></tr>';
	});
	html +='<tr height="30"><td colspan="8">'+'总共找到'+data.total+'条数据'+'</td></tr></table></div>';
	var	footerhtml='<input type="image" alt="Cancel" src="/CMS/images/box/cancel_button.gif" class="btn" id="cancelTerminal" onclick="$box(\'websiteTerminalHtmlcloseBtn\').onclick();"/>';
	Box("websiteTerminalHtml",900,350,html,footerhtml,920);
}